//
//  EditTagsViewController.m
//  parkour-photomap-ib
//
//  Created by Ed Mancebo on 4/5/11.
//  Copyright 2011 Personal. All rights reserved.
//

#import "EditTagsViewController.h"

@implementation EditTagsViewController

@synthesize keyboardToolbar, tag1, tag2, tag3, tag4, tag5, tag6;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	allTags = [[NSMutableArray alloc] init];
	[allTags addObject:tag1];
	[allTags addObject:tag2];
	[allTags addObject:tag3];
	[allTags addObject:tag4];
	[allTags addObject:tag5];
	[allTags addObject:tag6];
}

- (NSArray*) getTags {
	NSMutableArray *tagStrings = [[NSMutableArray alloc] init];
	
	for (UITextField *field in allTags) {
		if ([field.text length] != 0) {
			[tagStrings addObject:field.text];
		}
	}
	
	return [tagStrings autorelease];;
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (IBAction)hideKeyboard:(id)sender {
	for (UITextField *tf in allTags) {
		[tf resignFirstResponder];
	}
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
	
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
	
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

- (void)keyboardWillShow:(NSNotification *)notification {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
	
    CGRect frame = self.keyboardToolbar.frame;
    frame.origin.y = self.view.frame.size.height - 211.0;
    self.keyboardToolbar.frame = frame;
	
    [UIView commitAnimations];
}

- (void)keyboardWillHide:(NSNotification *)notification {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
	
    CGRect frame = self.keyboardToolbar.frame;
    frame.origin.y = self.view.frame.size.height;
    self.keyboardToolbar.frame = frame;
	
    [UIView commitAnimations];
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
	[allTags release];
	allTags = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
